package com.ncbee.base.util;

import java.security.MessageDigest;

/**
 * @Author: fengzirong
 * @Description:
 * @Date:Create in 16:05 2018/9/19
 */
public class StringUtils {
    /**
      * @param a  1,2,3 格式字符串
     * @param b   2
     * 目标结果  2,3
     * @return
     */
    public static String getUpdatePidStr(String a,String b){
        String c []=a.split(",");//目标数组
        int index=getArrayValueIndex(c,b);
        String pidStr="";
        for(int i=index;i<c.length;i++){
            if(i!=c.length-1){
                pidStr+=c[i]+",";
            }else{
                pidStr+=c[i];
            }
        }
        return pidStr;
    }
    //返回数组中的指定值。
    public static int getArrayValueIndex(String a[],String b){
        int p=-1;
        for(int i=0;i<a.length;i++){
            if(a[i].equals(b)){
                p=i;
                break;
            }
        }
        return p;
    }
    public static String getMd5Str(String source) {
        StringBuffer sb = new StringBuffer(32);
        try {
            MessageDigest md 	= MessageDigest.getInstance("MD5");
            byte[] array 		= md.digest(source.getBytes("utf-8"));
            for (int i = 0; i < array.length; i++){
                sb.append(Integer.toHexString((array[i] & 0xFF) | 0x100).toUpperCase().substring(1, 3));
            }
        } catch (Exception e){
            return null;
        }
        return sb.toString();
    }
    public static String getCustomMD5Str(String password){
        String firstMd5Val=getMd5Str(password);
        String salt=firstMd5Val.substring(firstMd5Val.length()-9,firstMd5Val.length()-8);
        String secondMd5Val=getMd5Str(firstMd5Val+salt);
        return secondMd5Val;
    }
}
